<%@ page language="java" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:useBean id="sql" class="com.tzq.JAVABEAN.ConnectDB" scope="page" />
<%
	String Sessionid=null;
	if(session.getAttribute( "pid" )!=null){
		Sessionid=session.getAttribute( "pid" ).toString();
	}
	
	String vid = request.getParameter( "vid" );
	if( vid == null) {
		out.println("Wrong vid.");
		return;
	}
	String sqlContent = new String( "SELECT * FROM Videos WHERE VideoID = ?" );
	ResultSet rs = sql.executeQuery(sqlContent, new String[]{vid}, new boolean[]{true});
%>
	<meta http-equiv="content-type" content="text/html" />
	<meta name="author" content="blog.anchen8.net" />
	<title>毕业生，你的选择</title>
    <link rel="stylesheet" type="text/css" href="../css/ShowVideo.css" />
    <link rel="stylesheet" type="text/css" href="../css/ShowBlogContext.css" />
    <script src="../js/jQuery1.82.js" type="text/javascript"></script>
    <script type='text/javascript' src='../js/jwplayer.js'></script>
    <script type="text/javascript">
        function createMain(){
            var _scrollWidth=Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            var _scrollHeight=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
                document.getElementById("main").style.left=(_scrollWidth-950)/2+"px";
               // document.getElementById("m").style.height=_scrollHeight+"px";
        }
        function naviover(val){
            document.getElementById(val).style.backgroundColor="#E1DACF";
        }
        function naviout(val){
            document.getElementById(val).style.backgroundColor="#C5C5C5";
        }
        
        function getCom(page){
        	$.post("/Bys-Website/PersonBlog/GetBlogComment",{
        		method:2,
				requestPage: page,
				VideoID:$("#vid").val()
			},function(data){
				var json = data.comment;
				$(".commshow").remove();
				$("#nextpage").remove();
				$("#prepage").remove();
				for(var i=0;i<(json.length-1);i++){
					if(json[i].Commenterid==5000032){
						$("#CommentShow").append("<div class='commshow'><ul><li>"+json[i].CommenterName+"</li><li>评论时间："+json[i].CommentDate+"</li></ul><br/><p>"+json[i].CommentText+"</p></div>");
					}else{
						$("#CommentShow").append("<div class='commshow'><ul><li><a href='../PersonMainPage.jsp?userID="+json[i].Commenterid+"'>"+json[i].CommenterName+"</a></li><li>评论时间："+json[i].CommentDate+"</li></ul><br/><p>"+json[i].CommentText+"</p></div>");
					} 
				}
				$("#totalSet").attr("value",json[json.length-1].totalSet+"条评论");
				if(json[json.length-1].curPage<json[json.length-1].totalPage){
					$("#CommentShow").append("<input type='button' id='nextpage'  dir='"+json[json.length-1].curPage+"' value='下一页'/>");
				}
				if(json[json.length-1].curPage>1){
					$("#CommentShow").append("<input type='button' id='prepage' dir='"+json[json.length-1].curPage+"' value='上一页'>");
				}
			},"json");
        }
        
        $(document).ready(function() {
        	getCom(1);
			/*	2nd example	*/
			
			$("#menu2 li a").wrapInner( '<span class="out"></span>' );
			
			$("#menu2 li a").each(function() {
				$( '<span class="over">' +  $(this).text() + '</span>' ).appendTo( this );
			});

			$("#menu2 li a").hover(function() {
				$(".out",	this).stop().animate({'top':	'45px'},	200); // move down - hide
				$(".over",	this).stop().animate({'top':	'0px'},		200); // move down - show

			}, function() {
				$(".out",	this).stop().animate({'top':	'0px'},		200); // move up - show
				$(".over",	this).stop().animate({'top':	'-45px'},	200); // move up - hide
			});
			
			
			/*Get next page commentText*/
			$("#nextpage").live("click", function(){
				var page = parseInt($("#nextpage").attr("dir"))+1;
				getCom(page);
				});
			/*Get preceding page commentText*/
			$("#prepage").live("click", function(){
				var page = parseInt($("#prepage").attr("dir"))-1;
				getCom(page);
			});
			/*send commentText*/
			$("#sendComment").click(function(){
				$.post("/Bys-Website/PersonBlog/Comment",{
					method:"2",
					VideoID:$("#vid").val(),
					commenterid:$("#commenterid").val(),
					commenttext:$("#texta").val()
				},function(data){
					if(data=="yes"){
						$("#texta").val("");
						getCom(1);
					}
				});
			});

		});
    </script>
</head>
<body class="body">
    <div class="main" id="main">
        <div id="videode">
<%
	if(rs.next()) {
%>
            <div class="videotitle">
                &nbsp;视频播放&nbsp;&nbsp;<%=rs.getString("VideoTitle") %>
            </div>
			<div class="videoPos">
				<div id="mediaspace">Wrong Video ID</div>
			</div>
<%
	sql.updatesql("UPDATE Videos SET ClickTimes=ClickTimes+1 WHERE VideoID = ?", new String[]{rs.getString("VideoID")}, 1, new int[]{1});		
%>
	<script type='text/javascript'>
	  jwplayer('mediaspace').setup({
	    'flashplayer': '../swf/player.swf',
	    'file': '<%=request.getContextPath() %><%=new String(rs.getString("VideoPath").getBytes("UTF-8"),"GBK") %>',
	    'autostart': 'true',
	    'controlbar': 'bottom',
	    'width': '900',
	    'height': '500'
	  });
	</script>
	<%
	}
	// update Video Click Times.	
	rs.close();
	sql.closeConnection();
%>
            <div id="CommentShow" class="commout">
                <input id="totalSet" type="button" value="" class="comti"/>
                <div class="blogashr"></div>
            </div>
             	<form>
	            <div class="comment">
	            	<textarea id="texta" rows="4" cols="100" dir="发表评论" style="color: #777;" onfocus="if(this.value==this.getAttribute('dir')){this.value=''} this.style.color='#000'" onblur="if(this.value==''){this.value=this.getAttribute('dir')}this.style.color='#777'">发表评论</textarea>
	            </div>
	            <div class="commsub">
	             	<div class="commbtn">
	                    <input id="sendComment" type="button" value="发表评论"/>
	                    <input id="vid" type="hidden" value="<%=vid %>"/>
	                    <input id="commenterid" type="hidden" value="<%=Sessionid%>"/>
	                </div>
	        	</div>
        		</form>
        </div>
    </div>
    <script>    
        createMain();
    </script>
    <div class="topbar">
        <div class="logo">
            <a href="/Bys-Website/Public/home.jsp">
            	<img src="/Bys-Website/SourceImageFile/toplogo.jpg"/>
            </a>
        </div>
        <div class="navi">
            <ul class="naviul">
                <li><a href="/Bys-Website/Public/Video.jsp" class="outli">视频</a></li>
				<li><a href="/Bys-Website/Public/Photo.jsp" class="outli">相册</a></li>
				<li><a href="/Bys-Website/Public/Blog.jsp" class="inli">博客</a></li>
            </ul>
        </div>
        <div class="loginfo">
           <ul class="loginfoul">
				<%if(session.getAttribute("pid")==null){%>
				<li><a href="/Bys-Website/Log_in.jsp">登录</a></li>
				<li><a href="/Bys-Website/Regist.jsp">注册</a></li>
			<%}else{%>
				<li><a href="../PersonMainPage.jsp?userID=<%=Sessionid  %>"><%=session.getAttribute("username").toString()%></a></li>
				<li><a href="../LoginServlet?method=1">退出</a></li>
			<%}%>
			</ul>
        </div>
    </div>
</body>
</html>